#include "../base/SampleBase.h"
#include "../base/D3DUtil.h"
#include "../base/SkyDome.h"

class SkyBoxTest : public SampleBase
{
private:
	SkyDome    *m_skyDome;
public:
	virtual bool Setup()
	{
		// Set light
		D3DXVECTOR3  dir(0.707f, 0.0f, 0.707f);
		D3DXCOLOR    col(1.0f, 1.0f, 1.0f, 1.0f);
		D3DLIGHT9    light = d3dutil::InitDirectionalLight(&dir, &col);

		m_device->SetLight(0, &light);
		m_device->LightEnable(0, true);
		m_device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
		m_device->SetRenderState(D3DRS_SPECULARENABLE,   false);

		// Set view matrix
		D3DXVECTOR3  pos(0.0f, 2.0f, -10.f);
		D3DXVECTOR3  target(0.0f, 0.0f, 0.0f);
		D3DXVECTOR3  up(0.0f, 1.0f, 0.0f);

		D3DXMATRIX  V;
		D3DXMatrixLookAtLH(&V, &pos, &target, &up);
		m_device->SetTransform(D3DTS_VIEW, &V);

		// Set Projection Matrix
		D3DXMATRIX  proj;
		D3DXMatrixPerspectiveFovLH(
			&proj,
			D3DX_PI  * 0.25f, 
			(float)m_windowWidth / (float) m_windowHeight,
			1.0f, 
			1000.0f);
		m_device->SetTransform(D3DTS_PROJECTION, &proj);

		m_skyDome = new SkyDome(m_device, 3.0, 10, 10);
		m_skyDome->Init();
		return true;
	}

	virtual void Cleanup()
	{
		delete m_skyDome;
	}


	bool Display(float timeDelta)
	{
		m_device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		m_device->BeginScene();

		m_skyDome->Render();

		m_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
		m_device->EndScene();
		m_device->Present(0, 0, 0, 0);

		return true;
	}
};
